package com.action.addrbook;

import com.db.addrbook.AddrBookDAO;
import com.db.addrbook.CategoryDAO;

public class AddrDeleteAction {
	private int addrno;
	private String selected;
	private AddrBookDAO abDAO;
	
	public void setAbDAO(AddrBookDAO abDAO) {
		this.abDAO = abDAO;
	}
	public void setSelected(String selected) {
		this.selected = selected;
	}
	public void setAddrno(int addrno) {
		this.addrno = addrno;
	}
	
	// 1개 삭제
	public String execute(){
		String result = "";	
		try {			
			result = "success";
			abDAO.deleteAddrBook(addrno);
		} catch (Exception e) {
			result = "error";
			System.out.println("CategoryDeleteAction.execute():"+e.toString());
		}
		return result;		
	}
	
	// 선택 삭제 (하나의 문자열로 합쳐져 넘어온 선택값들을 분리해 처리)
	public String deleteSelected(){
		String result = "";			
		String abs[] = selected.split("\\|");
		try {			
			for(int i=0; i<abs.length; i++){
				int delno = Integer.parseInt(abs[i]);
				abDAO.deleteAddrBook(delno);
			}
			result = "success";			
		} catch (Exception e) {
			result = "error";
			System.out.println("CategoryDeleteAction.delSelected():"+e.toString());
		}
		return result;		
	}
}
